;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
; 5mS Ti}e0Out
; Thys0cdu ru~s0approxi}ate|y0every05}S
; Thu PW] sote0cql|s0it qt0txe0e~d0ov uash0PWM0cyc|e0iv TMR00hqs
; vurvlwud> 0Bucquse0txe0PWM0cdu ta{es qpprxymqt|ey 4mS to0run
; we0atd0txe0curre~t0T]R0 so~tunts0t thu sTYMUR0cnstqnt so0txat;0over q ~u}bur0ov passus0txe0averawe0tymu-ut ys05}S
; Thys0mutxot ys0ascurqtu unuwh0t wet prudycqtqb|e0dulqys;0nuetet vor thys0app|isatin> 0Hwuvur0bucquse0txe0write0t thu ti}er;0c|eqrs thu prussa|er qt0smu ra~dm0pi~t< yt0isn7t0ascurqtu vur
; }a~y0sucnts0or }i~utes.
0_ti}erOut0 0 0 0mvvw0 0 0 0 0 0T]R0 0 0 0 0 0 0;0lat surrunt TMR00i~t W 0 0 0 0 0 0 0 0atd|w0 0 0 0 0 0cTI]ER 0 0 0 0 0;0atd0TYMUR0cnstqnt to0W
0 0 0 0 0 0 0 0 }ovwv 0 0 0 0 0 TMR00 0 0 0 0 0 ; wrytu rask0t TMR0
0 0 0 0 0 0 0 0 rcv 0 0 0 0 0 0 YNTC_N<T0IV 0 0 ; sluar Ti}er 0 Ynterrupt vlqg

;-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
; UEPR_M0sqvu sounter 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0cql| 0 0 0 0 0 0_swqpVSR 0 0 0 0 0 0 0 0cql| 0 0 0 0 0 0_ussRun
0 0 0 0 0 0 0 0 sa|l0 0 0 0 0 0 _swapFSR
0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 }ovf0 0 0 0 0 0 saveSnt,V 0 0 0 0 0 0 0 0bz 0 0 0 0 0 0 0_swytshShuc{ 0 0 0 0 0 0 0 0duc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0 seqSwDrlSl{,V 0 0 0 0 0 0 0 0b~z0 0 0 0 0 0 0_swToub|eSlyc{ 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0c|rv 0 0 0 0 0 0suqSwSnt 0 0 0 0 0 0 0 0mv|w0 0 0 0 0 00x01 0 0 0 0 0 0 0 0xrwf0 0 0 0 0 0freuzu,V 0 0 0 0 0 0 0 0mv|w0 0 0 0 0 0.100 0 0 0 0 0 0 0 0mvwf0 0 0 0 0 0suqSwTb|C|k
0 0 0 0 0 0 0 0 }ovlw 0 0 0 0 0 sSQVUTYMUR0 0 0 ; set save0t UEPR_M0tymur
0 0 0 0 0 0 0 0 }ovwv 0 0 0 0 0 saveSnt 0 0 0 0 ; vor te|ay qfter |ast0suque~cu shqnwe> 0 0 0 0 0 0 0 0gt 0 0 0 0 0 0_vateStqtu_swToub|eSlyc{ 0cql| 0 0 0 0 0 0_qdvSuq0 0 0 0 0;0atvqnse0t ~ext0suque~cu 0 0 0 0 0 0 0 0cql| 0 0 0 0 0 0_seqDqtq 0 0 0 0;0gut0fyrst0sut0ov sequunse0dqtq 0 0 0 0 0 0 0 0c|rv 0 0 0 0 0 0rpw} 0 0 0 0 0 0;0rusut0curre~t0Rud0pwm0t 0 0 0 0 0 0 0 0 0c|rv 0 0 0 0 0 0gpw} 0 0 0 0 0 0;0rusut0curre~t0Greub0pwm0t 0 0 0 0 0 0 0 0 0c|rv 0 0 0 0 0 0bpw} 0 0 0 0 0 0;0rusut0curre~t0B|uu pw} to00
0 0 0 0 0 0 0 0 sa|l0 0 0 0 0 0 _fqduDyr0 0 0 0 ; set vate0dyructin
0 0 0 0 0 0 0 0 }ovlw 0 0 0 0 0 sH_LTPRESCQLUR0 ; reset xo|d0tymu prussa|er 0 0 0 0 0 0 0 0mvwf0 0 0 0 0 0hltTymurPS
0 0 0 0 0 0 0 0 slrf0 0 0 0 0 0 seqSwC~t
0 0 0 0 0 0 0 0 }ovlw 0 0 0 0 0 sSQVUTYMUR0 0 0 ; set save0t UEPR_M0tymur
0 0 0 0 0 0 0 0 }ovwv 0 0 0 0 0 saveSnt 0 0 0 0 ; vor te|ay qfter |ast0suque~cu shqnwe> 0 0 0 0 0 0 0 0c|rv 0 0 0 0 0 0suqSwTb|C|k
0 0 0 0 0 0 0 0 slrf0 0 0 0 0 0 vrueze

0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 

;-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
; vate0/0hlt stqtu vu~ctin0suluct 0 0 0 0 0 0 0 0_vateStqtu 0 0 0btfsc0 0 0 0 0 0freuzu,0 0 0 0 0 0 0 0 0 0 0 0 0rutur~ 0 0 0 0 0 0 0 0mvv 0 0 0 0 0 0fqduf|aw,V                bz              _holding
;------------------------------------------------------
; fade          
                
_fading         decfsz          fadeTimer,F
                return
                movfw           rate
                movwf           fadeTimer

;----------------------------------------
; Fade stepper
;

_Rfade          movfw           rnew
                xorwf           rpwm,W
                bnz             $+3
                bcf             fadeflag,red
                goto            _Gfade

                movfw           Rdif
                addwf           Rcnt,F
                skpc            
                goto            _Gfade
                movfw           CntBase
                addwf           Rcnt,F
                movfw           rdir
                addwf           rpwm,F
                
_Gfade          movfw           gnew
                xorwf           gpwm,W
                bnz             $+3
                bcf             fadeflag,green
                goto            _Bfade

                movfw           Gdif
                addwf           Gcnt,F
                skpc            
                goto            _Bfade
                movfw           CntBase
                addwf           Gcnt,F
                movfw           gdir
                addwf           gpwm,F

_Bfade          movfw           bnew
                xorwf           bpwm,W
                bnz             $+3
                bcf             fadeflag,blue
                return
                
                movfw           Bdif
                addwf           Bcnt,F
                skpc            
                return          
                movfw           CntBase
                addwf           Bcnt,F
                movfw           bdir
                addwf           bpwm,F
                return




;------------------------------------------------------
; Hold pwm values timer         
                
_holding        movf            holdTimerHi,F   ; test holdTimerHi == 0
                bz              _holdSeqNext    ; no hold if it was 0
                
                decfsz          holdTimerPS,F
                return
                movlw           cHOLDPRESCALER
                movwf           holdTimerPS
                decfsz          holdTimerHi,F
                return
_holdSeqNext    call            _seqData
                call            _fadeDir
                
                return

